package com.powernode.controller;

import com.powernode.dto.OrderConfirmParam;
import com.powernode.service.OrderService;
import com.powernode.utils.AuthUtil;
import com.powernode.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Builder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 内容:
 * 作者: cy
 */

@RestController
@Api(tags = "订单管理")
@RequestMapping("p/myOrder")
public class OrderController {

   @Autowired
   private OrderService orderService;

   @PostMapping("confirm")
   @ApiOperation("订单确认")
   public ResponseEntity<OrderVo> orderConfirm(@RequestBody OrderConfirmParam orderConfirmParam){
      String openId = AuthUtil.getOpenId();
      OrderVo orderVo = orderService.orderConfirm(openId, orderConfirmParam);
      return ResponseEntity.ok(orderVo);

   }
   @PostMapping("submit")
   @ApiOperation("下预订单")
   public ResponseEntity<String> doSubmit(@RequestBody OrderVo orderVo) {
      String openId = AuthUtil.getOpenId();
      String orderSn = orderService.doOrder(openId, orderVo);
      // 这里后端的返回值 特别注意 如果是一个长的纯数字
      // 返回给前端会有什么问题？？ 丢失精度   346846346464612311110  ajax ->   XmlHttpRequest  XHR
      return ResponseEntity.ok("orderSn:" + orderSn);
   }

}
